package com.example.mytayunapi.Controller;

import com.example.mytayunapi.Entity.conversationInfo;
import com.example.mytayunapi.Entity.messageInfo;
import com.example.mytayunapi.Service.conversationInfoService;
import com.example.mytayunapi.Vo.ConversionProductUser;
import org.apache.logging.log4j.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.message.MessageInfo;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("con")
public class conversationController {
    @Autowired
    private conversationInfoService conversationService;

    @GetMapping("/other")
    public List<ConversionProductUser> getAllConversion(String User_id) {
        return conversationService.getAllConversion(User_id);
    }

    @GetMapping("/message")
    public List<messageInfo> getMessageByConversation(Integer Conversation_id) {
        return conversationService.getMessageByConversation(Conversation_id);
    }

    @PostMapping("/send")
    Integer sendMessage(@RequestBody messageInfo messageinfo) {
        return conversationService.insertMessage(messageinfo);
    }


    //http://localhost:8080/con/insert
    @PostMapping("/insert")
    Integer insertMessage(@RequestBody conversationInfo conversationInfo) {
        return conversationService.insertConversation(conversationInfo);
    }
}
